package com.atguigu.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;


/**
 * @ClassName RedisConfig
 * @Description TODO
 * @Detail Redis的配置类
 *          由于使用spring-boot-starter-data-redis这个依赖会有冲突，所以本项目使用spring-data-redis加上jedis依赖
 *          不过使用那两个依赖就需要配置一个redis，具体配置如下
 * @Author MyPC
 * @Date 2020/7/7
 * @Version 1.0
 */
@Configuration
public class RedisConfig {
    //注入有关RedisTemplate
    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
        RedisTemplate<String,Object> template=new RedisTemplate<>();
        template.setConnectionFactory(factory);
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new StringRedisSerializer());
        return template;
    }
}
